package cn.edu.sasu.controller;


import cn.edu.sasu.common.annotation.RoleNum;
import cn.edu.sasu.common.base.LayuiRespResult;
import cn.edu.sasu.common.base.RespResult;
import cn.edu.sasu.common.constants.Role;
import cn.edu.sasu.domain.dto.SysUserSaveDTO;
import cn.edu.sasu.domain.entity.SysDept;
import cn.edu.sasu.domain.vo.SysUserInfoVO;
import cn.edu.sasu.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 王尧
 * @since 2024-04-27
 */
@RestController
@RequestMapping("/api/sys_dept")
public class DeptController {


    @Autowired
    private IDeptService deptService;


    /*查询系统部门*/
    @RoleNum(Role.COMMON)
    @GetMapping("/findSysDeptAll")
    public LayuiRespResult findSysDeptAll(Integer page, Integer limit) {
        return deptService.findSysDeptAll(page, limit);
    }


    /*根据部门的名称查询*/
    @RoleNum(Role.COMMON)
    @GetMapping("/search")
    public LayuiRespResult search(Integer page,Integer limit,String deptName){
        return deptService.search(page,limit,deptName);
    }



    /*添加部门信息*/
    @RoleNum(Role.COMMON)
    @PostMapping("/save")
    public RespResult save(@RequestBody @Validated SysDept dept){
        return deptService.save(dept);
    }



    /*获取所有的部门*/
    @RoleNum(Role.COMMON)
    @GetMapping("/findSysDepts")
    public LayuiRespResult findSysDepts(){
        return deptService.findSysDepts();
    }


    /*根据id删除部门*/
    @RoleNum(Role.ADMIN)
    @PostMapping("/del")
    public RespResult del(Integer deptId){
        return deptService.delSysDeptByDeptId(deptId);
    }

    /*根据id集合，批量删除*/
    @RoleNum(Role.ADMIN)
    @PostMapping("/batchdel")
    public RespResult batchdel(Integer[] deptIds){
        return deptService.batchdel(deptIds);
    }


    @RoleNum(Role.ADMIN)
    @PostMapping("/updateInfo")
    public RespResult updateInfo(@RequestBody SysDept dept){
        return deptService.updateInfo(dept);
    }

}
